#include "econtainer.h"

eContainer::eContainer(int x,int y,int w,int h,std::string ptip) : Fl_Group(x,y,w,h)
{
    box(FL_PLASTIC_DOWN_BOX);
    color(FL_SELECTION_COLOR);
    sahip=parent();
    b1 = new eDragBox(x, y, TL);
    b2 = new eDragBox(x+w-10, y+h-10, BR);
    inner = new Fl_Group(x+5, y+5, w-10, h-10);
    inner->when(FL_WHEN_RELEASE);
    inner->callback(innerClick_CB,this);
    tip=ptip;
        if(tip=="Radio")
        {
            Fl_Round_Button *ic=new Fl_Round_Button(x+5,y+5,w-10,h-10,"Radio");
            ic->box(FL_PLASTIC_DOWN_BOX);
            ic->labelsize(12);
            icerik=ic;
        }
        else if(tip=="Check")
        {
            Fl_Check_Button *ic=new Fl_Check_Button(x+5,y+5,w-10,h-10,"Check");
            ic->labelsize(12);
            ic->box(FL_PLASTIC_DOWN_BOX);
            icerik=ic;
        }
        else if(tip=="Label")
        {
            Fl_Input *ic=new Fl_Input(x+5,y+5,w-10,h-10,"");
            ic->when(FL_WHEN_ENTER_KEY_CHANGED);
            ic->textsize(12);
            ic->callback(metinYaz_CB,this);
            ic->box(FL_PLASTIC_DOWN_BOX);
            icerik=ic;
        }
        else if(tip=="Metin")
        {
            Fl_Multiline_Input *ic=new Fl_Multiline_Input(x+5,y+5,w-10,h-10,"");
            ic->box(FL_PLASTIC_DOWN_BOX);
            ic->textsize(12);
            ic->when(FL_WHEN_CHANGED);
            ic->callback(metinYaz_CB,this);
            icerik=ic;
        }
        else if(tip=="Resim")
        {
            Fl_Input *ic=new Fl_Input(x+5,y+5,w-10,h-10,"");
            ic->box(FL_PLASTIC_DOWN_BOX);
            ic->textsize(12);
            ic->when(FL_WHEN_CHANGED);
            ic->callback(metinYaz_CB,this);
            icerik=ic;
        }
        else if(tip=="Anim")
        {
            Fl_Input *ic=new Fl_Input(x+5,y+5,w-10,h-10,"");
            ic->box(FL_PLASTIC_DOWN_BOX);
            ic->textsize(12);
            ic->when(FL_WHEN_CHANGED);
            ic->callback(metinYaz_CB,this);
            icerik=ic;
        }
    inner->end();
    inner->box(FL_THIN_DOWN_BOX);
    resizable(inner);
    end();
    sildelete=false;
    xx=x-230;
    yy=y-30;
    genislik=w;
    yukseklik=h;
    fkirmizi=0;
    fmavi=0;
    fyesil=0;
    byesil=0;
    bmavi=0;
    bkirmizi=0;
    yatay=1;
    dikey=1;
    font="bas_1";
    metin="";
    fontid=0;
    hiz=0;
}

eContainer::~eContainer()
{
    //dtor
}

int eContainer::handle(int event)
{
    EBoard *ps=(EBoard *)parent()->parent();
    Ewindow *ew=(Ewindow *)ps->parent();
    int ret=Fl_Group::handle(event);
    if(ret)
        return ret;
    static int butx=0;
    static int buty=0;
    switch(event)
    {
        case FL_PUSH:
            butx=x()-Fl::event_x();
            buty=y()-Fl::event_y();
            ps->secim=this;
            xx=x()-225;
            yy=y()-25;
            genislik=this->w()-20;
            yukseklik=this->h()-20;
            ew->propertiesTimer(this);
            ret=1;
            break;
        case FL_DRAG:
            int xx1=butx+Fl::event_x();
            int yy1=buty+Fl::event_y();
            if(xx1>=sahip->x() && yy1>=sahip->y()+15 && xx1<=sahip->w()+230-w() && yy1<=sahip->h()-h()+15)
            {
                position(xx1,yy1);
                genislik=this->w()-10;
                yukseklik=this->h()-10;
                xx=xx1-225;
                yy=yy1-25;
                ew->propertiesTimer(this);
                ps->redraw();
                redraw();
            }
            ret=1;
            break;
        case FL_KEYDOWN:
            if(Fl::event_key()==FL_Delete)
            {
                sildelete=true;
            }
            break;
    }
    return ret;
}
std::string eContainer::tipgonder()
{
    return tip;
}

bool eContainer::deletesil()
{
    return sildelete;
}
Fl_Widget *eContainer::icerikgonder()
{
    return icerik;
}
void eContainer::innerClick_CB(Fl_Widget *p, void *userdata)
{
    eContainer *gecici=(eContainer *)userdata;
    gecici->innerClick_CB2();
}
void eContainer::innerClick_CB2()
{
    if(Fl::event_key()==FL_Delete)
        sildelete=true;
}

int eContainer::xxgonder()
{
    return xx;
}
int eContainer::yygonder()
{
    return yy;
}
int eContainer::genislikgonder()
{
    return genislik;
}
int eContainer::yukseklikgonder()
{
    return yukseklik;
}
int eContainer::fmavigonder()
{
    return fmavi;
}
int eContainer::fyesilgonder()
{
    return fyesil;
}
int eContainer::fkirmizigonder()
{
    return fkirmizi;
}
int eContainer::byesilgonder()
{
    return byesil;
}
int eContainer::bmavigonder()
{
    return bmavi;
}
int eContainer::bkirmizigonder()
{
    return bkirmizi;
}
int eContainer::yataygonder()
{
    return yatay;
}
int eContainer::dikeygonder()
{
    return dikey;
}
int eContainer::fontgonder()
{
    return fontid;
}
std::string eContainer::metingonder()
{
    return metin;
}

void eContainer::enboy(int g,int y)
{
    genislik=g;
    yukseklik=y;
}
void eContainer::pozisyon(int g,int y)
{
    xx=g;
    yy=y;
}

void eContainer::fmavial(int pf)
{
    fmavi=pf;
}
void eContainer::fyesilal(int pf)
{
    fyesil=pf;
}
void eContainer::fkirmizial(int pf)
{
    fkirmizi=pf;
}
void eContainer::bmavial(int pb)
{
    bmavi=pb;
}
void eContainer::byesilal(int pb)
{
    byesil=pb;
}
void eContainer::bkirmizial(int pb)
{
    bkirmizi=pb;
}
void eContainer::yatayal(int py)
{
    yatay=py;
}
void eContainer::dikeyal(int pd)
{
    dikey=pd;
}
void eContainer::fontal(std::string ptext,int pid)
{
    font=ptext;
    fontid=pid;
}
void eContainer::metinal(std::string ptext)
{
    metin=ptext;
    if(tip=="Radio" || tip=="Check")
        icerik->label(metin.c_str());
}

void eContainer::metinYaz_CB(Fl_Widget *p, void *userdata)
{
    eContainer *gecici=(eContainer *)userdata;
    gecici->metinYaz_CB2(p);
}
void eContainer::metinYaz_CB2(Fl_Widget *p)
{
    EBoard *ps=(EBoard *)parent()->parent();
    Ewindow *ew=(Ewindow *)ps->parent();
    if(tip=="Metin")
    {
        Fl_Multiline_Input *gecici=(Fl_Multiline_Input *)p;
        metin=gecici->value();
    }
    else if(tip=="Label")
    {
        Fl_Input *gecici=(Fl_Input *)p;
        metin=gecici->value();
    }
    ew->propenceregonder()->metingonder()->value(metin.c_str());
}
void eContainer::hizal(int ph)
{
    hiz=ph;
}
int eContainer::hizgonder()
{
    return hiz;
}
std::string eContainer::fonttextgonder()
{
    return font;
}
